package com.shuma.auth.controller;

import com.shuma.auth.entity.RestBean;
import com.shuma.auth.model.po.ProductCategory;
import com.shuma.auth.service.ProductCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lele
 */
@Slf4j
@RestController
@RequestMapping("productCategory")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 查一级分类
     */
    @GetMapping("/type")
    public RestBean<List<ProductCategory>> listType(){
        List<ProductCategory> productCategories = productCategoryService.listType();
        return RestBean.success(productCategories);
    }

    /**
     * 根据一级分类查二级分类
     */
    @GetMapping("/category/{typeId}")
    public RestBean<List<ProductCategory>> listCategory(@PathVariable String typeId){
        List<ProductCategory> productCategories = productCategoryService.listCategory(typeId);
        return RestBean.success(productCategories);
    }

}
